package com.chatplus.application.domain.response.admin;

import com.chatplus.application.domain.entity.file.SysOssEntity;
import com.chatplus.application.json.Int64AsString;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;

/**
 * OSS对象存储视图对象 sys_oss
 */
@Data
public class SysOssResponse implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;
    /**
     * 对象存储主键
     */
    @JsonSerialize(using = Int64AsString.class)
    private Long id;
    /**
     * 文件名
     */
    private String fileName;
    /**
     * 原名
     */
    private String originalName;
    /**
     * 文件后缀名
     */
    private String fileSuffix;
    /**
     * 文件类型
     */
    private String contentType;
    /**
     * URL地址
     */
    private String url;
    /**
     * 服务商
     */
    private String service;
    /**
     * 文件hash值，用于去重
     */
    private String hashId;

    public static SysOssResponse build(SysOssEntity sysOssEntity) {
        if (sysOssEntity == null) {
            return null;
        }
        SysOssResponse sysOssResponse = new SysOssResponse();
        sysOssResponse.setId(sysOssEntity.getId());
        sysOssResponse.setFileName(sysOssEntity.getFileName());
        sysOssResponse.setOriginalName(sysOssEntity.getOriginalName());
        sysOssResponse.setFileSuffix(sysOssEntity.getFileSuffix());
        sysOssResponse.setContentType(sysOssEntity.getContentType());
        sysOssResponse.setUrl(sysOssEntity.getUrl());
        sysOssResponse.setService(sysOssEntity.getService());
        sysOssResponse.setHashId(sysOssEntity.getHashId());
        return sysOssResponse;
    }
}
